<template>
  <div class="app-container">
    <wise-crud ref="wise-crud" :urls="urls" :fields="fields">
      <template v-slot:handle="slotProps">
        <el-button
          type="success"
          size="small"
          class="activeBtn"
          round
          @click.native.prevent="gotoEnterpriseManage(slotProps.row)"
        >企业管理</el-button>
      </template>
    </wise-crud>
  </div>
</template>

<script>
import WiseCrud from '@/components/Crud/wiseCrud'
import {
  setEntSpaceId
} from '@/utils/auth'
export default {
  name: 'EnterpriseManage',
  components: {
    WiseCrud
  },
  data() {
    let checkPhone = (rule, value, callback) => {
      const phoneReg = /^1[3|4|5|7|8][0-9]{9}$/
      if (!value) {
        return callback(new Error('电话号码不能为空'))
      }
      setTimeout(() => {
        if (!Number.isInteger(+value)) {
          callback(new Error('请输入数字值'))
        } else {
          if (phoneReg.test(value)) {
            callback()
          } else {
            callback(new Error('电话号码格式不正确'))
          }
        }
      }, 100)
    }
    let checkEmail = (rule, value, callback) => {
      const mailReg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/
      if (!value) {
        return callback(new Error('邮箱不能为空'))
      }
      setTimeout(() => {
        if (mailReg.test(value)) {
          callback()
        } else {
          callback(new Error('请输入正确的邮箱格式'))
        }
      }, 100)
    }
    return {
      urls: {
        list: '/api/v1/welder-sbtx-second/enterprise-comb/list',
        add: '/api/v1/welder-sbtx-second/enterprise-comb/create',
        show: '/api/v1/welder-sbtx-second/enterprise-comb/show/',
        update: '/api/v1/welder-sbtx-second/enterprise-comb/update/',
        delete: '/api/v1/welder-sbtx-second/enterprise-comb/remove/'
      },
      fields: [{
        label: '序号',
        type: 'index',
        use: ['table']
      },
      {
        label: '企业名称',
        prop: 'name',
        type: 'text',
        labelWidth: '130px',
        maxlength: 20,
        rules: [{
          required: true,
          message: '请输入企业名称',
          trigger: 'blur'
        }],
        placeholder: '请输入企业名称',
        use: ['table', 'add', 'view', 'edit', 'search']
      },
      {
        label: '企业logo',
        prop: 'picture',
        type: 'file',
        limit: 1,
        labelWidth: '130px',
        uploadType: 'image',
        rules: [{
          required: true,
          message: '请选择照片',
          trigger: 'change'
        }],
        use: ['table', 'add', 'view', 'edit']
      },
      {
        label: '企业管理员',
        type: 'render',
        tableRender: (h, row, index) => {
          return h(
            'div',
            row.entAdminUserInfo && row.entAdminUserInfo.length > 0
              ? row.entAdminUserInfo.map((item) => item.username).join('，')
              : ''
          )
        },
        viewRender: (h, item, object) => {
          return h(
            'div',
            object.entAdminUserInfo && object.entAdminUserInfo.length > 0
              ? object.entAdminUserInfo
                .map((item) => item.username)
                .join('，')
              : ''
          )
        },
        use: ['table', 'view']
      },
      // {
      //   label: "企业管理员",
      //   prop: "entAdminUserInfo",
      //   type: "render",
      //   labelWidth: "130px",
      //   viewRender: (h, item, object) => {
      //     return h(
      //       "div",
      //       object.entAdminUserInfo ? object.entAdminUserInfo.username : ""
      //     );
      //   },
      //   use: ["view"],
      // },
      // {
      //   label: "企业管理员",
      //   prop: "entAdmin",
      //   type: "select",
      //   labelWidth: "130px",
      //   url: "/api/v1/welder-uac-second/user-information-comb/get-user-info-filter-valid-list",
      //   labelKey: "username",
      //   valueKey: "userId",
      //   objParams: {
      //     key: "filterUserId",
      //     value: "entAdminUserId",
      //   },
      //   filtersObj: {
      //     roleCodes: ["entAdminUserId"],
      //   },
      //   objKeys: [
      //     {
      //       field: "entAdminUserId",
      //       key: "userId",
      //     },
      //   ],
      //   rules: [
      //     { required: true, message: "请选择企业管理员", trigger: "blur" },
      //   ],
      //   placeholder: "请选择企业管理员",
      //   use: ["add", "edit"],
      // },
      {
        label: '企业宣传图',
        prop: 'publicityPicture',
        type: 'file',
        labelWidth: '130px',
        uploadType: 'image',
        use: ['add', 'view', 'edit']
      },
      {
        label: '组织机构代码',
        prop: 'organization',
        type: 'text',
        labelWidth: '130px',
        rules: [{
          required: true,
          message: '请输入组织机构代码',
          trigger: 'blur'
        }],
        placeholder: '请输入组织机构代码',
        use: ['table', 'add', 'view', 'edit', 'search']
      },
      {
        label: '联系邮箱',
        prop: 'eamil',
        type: 'text',
        labelWidth: '130px',
        rules: [{
          required: true,
          message: '请输入联系邮箱',
          trigger: 'blur'
        }],
        placeholder: '请输入联系邮箱',
        use: ['table', 'add', 'view', 'edit', 'search']
      },
      {
        label: '单位电话',
        prop: 'phone',
        type: 'text',
        labelWidth: '130px',
        rules: [{
          required: true,
          message: '请输入单位电话',
          trigger: 'blur'
        }],
        placeholder: '请输入单位电话',
        use: ['table', 'add', 'view', 'edit', 'search']
      },
      {
        label: '法人代表',
        prop: 'legalPerson',
        type: 'text',
        labelWidth: '130px',
        tableWidth: '120px',
        rules: [{
          required: true,
          message: '请输入法人代表',
          trigger: 'blur'
        }],
        use: ['table', 'add', 'view', 'edit', 'search']
      },
      {
        label: '单位传真',
        prop: 'fax',
        type: 'text',
        labelWidth: '130px',
        placeholder: '请输入单位传真',
        use: ['add', 'view', 'edit']
      },
      {
        label: '邮政编码',
        prop: 'postalCode',
        type: 'text',
        labelWidth: '130px',
        placeholder: '请输入邮政编码',
        use: ['add', 'view', 'edit']
      },
      {
        label: '成立时间',
        prop: 'established',
        type: 'datetime',
        format: 'YYYY-MM-DD HH:mm:ss',
        labelWidth: '130px',
        maxlength: 1000,
        placeholder: '请选择成立时间',
        use: ['table', 'add', 'view', 'edit']
      },
      {
        label: '地址',
        prop: 'area',
        type: 'area',
        objKeys: [{
          field: 'provinceCode',
          key: 'province',
          value: 'key'
        },
        {
          field: 'provinceName',
          key: 'province',
          value: 'value',
          tableShow: true
        },
        {
          field: 'cityCode',
          key: 'city',
          value: 'key'
        },
        {
          field: 'cityName',
          key: 'city',
          value: 'value',
          tableShow: true
        },
        {
          field: 'countyCode',
          key: 'area',
          value: 'key'
        },
        {
          field: 'countyName',
          key: 'area',
          value: 'value',
          tableShow: true
        },
        {
          field: 'streetCode',
          key: 'town',
          value: 'key'
        },
        {
          field: 'streetName',
          key: 'town',
          value: 'value',
          tableShow: true
        }
        ],
        labelWidth: '130px',
        maxlength: 1000,
        placeholder: '请选择地址',
        use: ['table', 'add', 'view', 'edit']
      },
      {
        label: '详细地址',
        prop: 'address',
        type: 'text',
        labelWidth: '130px',
        placeholder: '请输入详细地址',
        use: ['table', 'add', 'view', 'edit', 'search']
      },
      {
        label: '备注',
        prop: 'remark',
        type: 'textarea',
        labelWidth: '130px',
        maxlength: 1000,
        placeholder: '请输入备注',
        use: ['add', 'view', 'edit']
      },
      // {
      //   label: "上传类型",
      //   type: "radio",
      //   prop: "bigScreenType",
      //   dataDic: "fileType",
      //   labelWidth: "130px",
      //   use: ["add", "view", "edit"],
      //   rules: [
      //     { required: true, message: "请选择上传类型", trigger: "blur" },
      //   ],
      // },
      // {
      //   label: "请上传",
      //   type: "file",
      //   prop: "bigScreenStr",
      //   labelWidth: "130px",
      //   uploadType: "image",
      //   use: ["add", "view", "edit"],
      // },
      // {
      //   label: "URL链接",
      //   type: "text",
      //   prop: "bigScreenStr",
      //   labelWidth: "130px",
      //   placeholder: "请输入URL地址",
      //   use: ["add", "view", "edit"],
      // },
      {
        label: '操作',
        type: 'handle',
        use: ['table'],
        handle: ['edit', 'view', 'delete'],
        tableWidth: '270px'
      }
      ],
      page: {
        p: 1,
        ps: 10
      },
      viewDrawer: false,
      total: 0,
      tableData: [],
      row: {}
    }
  },
  methods: {
    gotoEnterpriseManage(item) {
      setEntSpaceId(item.spaceId)
      window.location.href = '/enterprise'
      // window.open('/enterprise')
    }
  }
}
</script>

<style scoped>
</style>
